import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { Modal } from '@ant-design/react-native';
import PropTypes from 'prop-types';
import { delPlan, changePlanState } from '../../../../comconfig/sqlfun';
import { debounce } from '../../../../utils/common';

const Item = ({ navigation, objItem, getPlanList }) => (
    <View>
        <TouchableOpacity
            style={{
                marginTop: 7,
                height: 35,
                backgroundColor: '#FFFFFF',
                width: '100%',
                borderRadius: 5,
            }}
            onPress={() => Modal.operation([
                {
                    text: '删除',
                    onPress: () => {
                        delPlan(parseInt(objItem.planid, 10)); getPlanList();
                    },
                    style: { color: '#0F8DE9' },
                },
                {
                    text: '编辑',
                    onPress: () => debounce(() => navigation.push('添加计划',
                        { objItem, planid: objItem.planid, funList: { getPlanList } })),
                    style: { color: '#0F8DE9' },
                },
                {
                    text: '就绪',
                    onPress: () => {
                        changePlanState(parseInt(objItem.planid, 10), 1);
                        getPlanList();
                    },
                    style: { color: '#0F8DE9' },
                },
            ])}
        >
            <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
                <View style={{ marginLeft: 3 }}>
                    <Text style={{ fontSize: 18, marginTop: 4 }}>{objItem.title}</Text>
                </View>
            </View>
        </TouchableOpacity>
    </View>
);
Item.defaultProps = {
    objItem: {},
    getPlanList: () => {},
};
Item.propTypes = {
    objItem: PropTypes.objectOf(PropTypes.any),
    getPlanList: PropTypes.func,
};
export default Item;
